//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

package main;

import java.util.HashMap;
import java.util.Map;

//Clase usada para recuperar las diferentes traducciones
public class Language {

	private static Language idioma;
	private DadesUsuari dades;
	private String language;
	
	//Variable que guardara las traducciones con el siguiente formato
	//Map<Texto_a_traducir, Traduccion> donde texto a traducir se pondra en ingles
	private Map<String, String> translation;

	private Language() {
		dades = new DadesUsuari();
		language = dades.getLanguage();
		String rutaFitxer = "languages/" + language + ".txt";
		Fitxer ft = new Fitxer(rutaFitxer);

		translation = new HashMap<String, String>();

		String[] dada = new String[2];
		dada[0] = ft.linea();

		while (dada[0] != null) {
			dada = dada[0].split("=");
			translation.put(dada[0], dada[1]);
			dada[0] = ft.linea();
		}		
	}

	//Solo necesitamos un objeto de tipo Language, de ahi que se use el patron singleton
	public static Language getSingleton() {
		if (idioma == null) {
			idioma = new Language();
		}
		return idioma;
	}
	
	public Map<String, String> getTranslation(){
		return translation;
	}

}
